﻿using System;
using System.Configuration.Abstractions;

namespace Sustainalytics.Claims.Service
{
    public static class HostConfig
    {
        public static string GetHostUrl()
        {
            string url = ConfigurationManager.Instance.AppSettings.AppSettingSilent("httpHostUrl", () => "");

            var useHttps = ConfigurationManager.Instance.AppSettings.AppSettingSilent("UseHttps", () => true);
            if (useHttps)
            {
                var uriBuilder = new UriBuilder(url);
                uriBuilder.Scheme = Uri.UriSchemeHttps;
                uriBuilder.Port = ConfigurationManager.Instance.AppSettings.AppSettingSilent("httpsPort", () => 443);
                url = uriBuilder.Uri.ToString();
            }

            return url;
        }
    }
}
